<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <meta name="csrf_token" id="token" content="{{ csrf_token() }}">
    @include('public.h5_head')
    <title>确认订单</title>
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/rem.js"></script>
    <link href="{{env('CDN_DOMAIN_NAME')}}/css/font-awesome.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/commoncss/common.css"/>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/store/css/cart.css?v=1.3.0"/>
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/app.js"></script>
    <!-- <script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/4.2.5iscroll.js"></script> -->
    {{--省市区--}}
    <link href="{{env('CDN_DOMAIN_NAME')}}/store/prov/mui.poppicker.css?v=1.0.2" rel="stylesheet">
    <script src="{{ env('CDN_DOMAIN_NAME') }}/store/prov/mui.min.js"></script>
    <script src="{{ env('CDN_DOMAIN_NAME') }}/store/prov/mui.poppicker.js?v=1.0.3"></script>
    <script src="{{ env('CDN_DOMAIN_NAME') }}/store/prov/city.data.js?v=1.0.2"></script>
    <style media="screen">
      .wrap{position: absolute;z-index: 100;top:0;bottom:2.091rem;left: 0;width: 100%;overflow-y:auto;overflow-x:hidden;background:#f1f1f1;-webkit-overflow-scrolling:touch;}
      .wrap::-webkit-scrollbar{width:0;height:0}
      .cart .owns{
        height:1.5rem;
        font-size:0.555rem;
        padding:0 4%;
      }
      .send-place{
        display: block;
        width:100%;
        clear: both;
        font-size:0.555rem;
        height:1.5rem;
        line-height: 1.5rem;
        background-color:#fff;
        padding:0 4%;
        border-bottom:1px solid #e8e8e8;

      }
      .user_prov{
        border:none;
        outline: none;
        color:#000;
        font-size:0.555rem;
        margin-left:1.665rem;
      }
      .send-place-info{
        display: block;
        width:100%;
        clear: both;
        font-size:0.555rem;
        height:3.5rem;
        line-height: 1.4rem;
        background-color: #fff;
        padding:0 4%;
      }
      .edit-place-info{
        width:64%;
        display: inline;
        height:2rem;
        float: right;
        padding:2%;
        margin-top:2%;
        margin-right:10%;
        border: 1px solid gray;
      }
      .user_name{
        margin-left:1.665rem!important;
      }
      .popup,.choice{
        box-shadow: 0 0 5px #ccc;
      }
      .choice{
        height:5.4rem;
      }
      .tip_hide{height:2.517rem;width:7.528rem;line-height:2.517rem;text-align:center;color:#fff;background:#000;opacity:0.8;filter:alpha(opacity=80);-moz-border-radius:0.427rem;-webkit-border-radius:0.427rem;border-radius:0.427rem;font-size:0.683rem;position: absolute;top:-1.856rem;left:0;right:0;bottom:0;margin:auto;z-index:1000;}
      .cart_style i,.cart_style span{
        float: right;
      }
      .cart_style i{
        width: 0.6rem;
        height:0.6rem;
        cursor: pointer;
      }
      .cart_style i:first-child{
          padding-left:0.2rem;
          padding-right:0.1rem;
          cursor: pointer;
      }
      .cart_style i:last-child{
          padding-left:0.4rem;
          padding-right:0.2rem;
          cursor: pointer;
      }
      .cart_style span{
        width:1.2rem;
        text-align: center;
        line-height:0.555rem;
        font-size:0.555rem;
      }
      .cart_li{
          margin-bottom:0.54rem;
      }
    </style>
</head>
<body>
<div id="box_cart">
    <div class="wrap" id="#wrapper">
        <div class="cart">
            <span class="owns sp"><b>收件人信息</b></span>
            <span class="send-place">收件人<input type="text" class="inp user_prov user_name check_user_name" value=""></span>
            <span class="send-place">手机号<input type="text" class="inp user_prov user_name check_user_numb" value=""></span>
            <span class="send-place">省市区<input type="text" abc="" readonly class="inp user_prov check_user_prov" id="cityResult" value=""></span>
            <span class="send-place-info">详细地址
              <textarea class="edit-place-info"  maxLength="40"></textarea>
            </span>
            <div class="cart_wap" style="display:none;">
                <div class="cart_tips">还没有地址，去<b>填写</b>?</div>
                <div class="cart_address" >
                    <div class="jian"><i class="fa fa-angle-right fa-2x"></i></div>
                    <div class="cart_infos">

                    </div>
                    <div class="cart_details">收货地址: 大家客户端即可好的撒即可啥活动空间是7单元大家客户端即可好的撒即可啥活动空间是7单元大家客户端即可好的撒即可啥活动空间是7单元</div>
                </div>
            </div>
            <ul class="cart_ul" >
                <li class="cart_li">
                    <!-- <div class="lists">
                        <div class="cart_pic">
                            <img src="{{ env('CDN_DOMAIN_NAME').'/upload/default.png' }}" alt="" class="cart_img" />
                        </div>
                        <div class="cart_info">
                            <div class="cart_tit">
                                <p class="cart_text">【标题】</p>
                            </div>

                            <p class="cart_style">款号：G123-123<i class="fa fa-plus-circle fa-lg plus-num"></i><span abc="5" class="clo-nums">2</span><i class="fa fa-minus-circle fa-lg minus-num"></i></p>
                            <p class="cart_color">颜色：黑色</p>
                            <div class="cart_doble">
                                <p class="cart_size">尺码：13码</p>
                                <p class="cart_money"><i>￥</i>123</p>
                            </div>
                        </div>
                    </div> -->

                    <ol class="cart_btn">
                        <li class="info_li"><span>商品总价</span><span class="info_sp">￥<span class="sum_of_price"></span></span></li>
                        <li class="info_li"><span>邮费</span><span class="info_sp">￥<span class="postage_price"></span></span></li>
                    </ol>
                </li>
            </ul>
        </div>
    </div>
    <div class="par_now_box">
        <div class="par_now">
            <div class="money_c">合计 ￥<span class="fact_price"></span></div>
            <a onclick="checkPay()" class="go_pay">去付款</a>
        </div>
    </div>
    <div class="choice" style="display:none;">
        <div class="choiceT">
            <span class="choice_sp1">×</span>
            <span class="choice_sp2">请选择付款方式</span>
        </div>
        <div class="choiceC">
            <p class="choice_p" type="wx">
                <span class="bg_sp2"></span>
                <span class="choice_sp3">微信</span>
                <span class="choice_sp4"><i class="fa fa-circle-thin"></i></span>

            </p>
            <p class="choice_p" type="alipay">
                <span class="bg_sp3"></span>
                <span class="choice_sp3">支付宝</span>
                <span class="choice_sp4"><i class="fa fa-circle-thin"></i></span>

            </p>
        </div>
    </div>
    <div class="tip_hide" style="display:none;"></div>
    <div class="expurgate" style="display: none;"></div>
    <div class="mask" style="display:none;"></div>
</div>
</body>
<script>
//苹果叉
var str= navigator.userAgent.toLowerCase();
var ver=str.match(/cpu iphone os (.*?) like mac os/);
if(ver && $(window).width() === 375 && $(window).height() === 724 && window.devicePixelRatio === 3){
  $(".info_sub_box").css("height","3.52rem");
}
//禁止键盘弹出
$("#cityResult").focus(function(){
  document.activeElement.blur();
});
//省市区
(function($, doc) {
  $.init();
  $.ready(function() {
      var cityPicker= new $.PopPicker({
          layer: 3
      });
      cityPicker.setData(cityData);
      var cityResult = doc.getElementById('cityResult');
      cityResult.addEventListener('focus', function(event) {
          cityPicker.show(function(items) {
              cityResult.value=(items[0] || {}).text + " " + (items[1] || {}).text + " " + (items[2] || {}).text;
              cityResult.setAttribute('abc',(items[2] || {}).value);
              //返回 false 可以阻止选择框的关闭
              //return false;
          });
      });
  });
})(mui, document);
$.ajax({
    url:"/exchange/customer-order-pay-info",
    data:{
    },
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
    },
    type:'POST',
    dataType:'json',
    success:function(data){
        var sumMoney = new Number;
        $.each(data.content.pro_details,function(idx,obj){
            $('.cart_li').prepend("<div class='lists'><div class='cart_pic'><img src='{{ env('CDN_DOMAIN_NAME') }}/upload/"+obj.face+"' alt='' class='cart_img' /></div><div class='cart_info'><div class='cart_tit'><p class='cart_text'>"+obj.title+"</p></div><p class='cart_style'>款号："+obj.girard+"<i class='fa fa-plus-circle fa-lg plus-num'></i><span abc='"+obj.nums+"' class='clo-nums' price='"+obj.price+"'>"+obj.order_num+"</span><i class='fa fa-minus-circle fa-lg minus-num'></i></p><p class='cart_color'>颜色："+obj.color+"</p><div class='cart_doble'><p class='cart_size'>尺码：<span abc='"+obj.id+"'>"+obj.size+"</span>码</p><p class='cart_money'><i>￥</i><span>"+obj.price*obj.order_num+"</span></p></div></div></div>");
            sumMoney += obj.price*obj.order_num;
        });
        $('.sum_of_price').text(sumMoney);
        $('.postage_price').text(data.content.postage);
        $('.fact_price').text(sumMoney+data.content.postage);
    }
});
$.ajax({
    url:"/exchange/customer-address",
    data:{
    },
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
    },
    type:'POST',
    dataType:'json',
    success:function(data){
        if(data.result.success){
            $('.check_user_name').val(data.content.info.name);
            $('.check_user_numb').val(data.content.info.tel);
            $('.edit-place-info').val(data.content.address_details);
            $('.edit-place-info').text(data.content.address_details);
            $('.check_user_prov').val(data.content.address[0].area_name+' '+data.content.address[1].area_name+' '+data.content.address[2].area_name);
            $('.check_user_prov').attr('abc',data.content.address[2].area_bh);
        }else{

        }
    }
});
//保存
function checkPay(){
    if($('.sum_of_price').text() == 0){
        $('.tip_hide').html('至少购买一件');
        $('.tip_hide').show().delay(800).hide(0);
        return false;
    }
  var username=$(".check_user_name").val();
  if ( !(/^[\u4e00-\u9fa5]{2,8}$/.test( username )) ) {
      $('.tip_hide').html('姓名为2-4个中文字符');
      $('.tip_hide').show().delay(800).hide(0);
      return false;
  }
  var phone=$(".check_user_numb").val();
  var exp=/^1[34578]\d{9}$/;
  if(phone.length== 0){
      $('.tip_hide').html('手机号不能为空');
      $('.tip_hide').show().delay(800).hide(0);
      return false;
  }
  if(!exp.test(phone)){
      $('.tip_hide').html('手机号格式不正确');
      $('.tip_hide').show().delay(800).hide(0);
      return false;
  }
  var counts=$(".check_user_prov").val();
  if(counts==''){
      $('.tip_hide').html('请选择省市区');
      $('.tip_hide').show().delay(800).hide(0);
      return false;
  }else{
      var area_code=$(".check_user_prov").attr("abc");
      var arr=counts.split(" ");
      var province=arr[0];
      var city=arr[1];
      var count=arr[2];
  }
  var area_details=$(".edit-place-info").val();
  if ( area_details=='' ) {
      $('.tip_hide').html('请填写详细地址');
      $('.tip_hide').show().delay(800).hide(0);
      return false;
  }
  var that=this;
  $('.choice').show();
  $('.mask').show();
}
$('.choice_sp1').click(function(){
  $('.choice').hide();
  $('.mask').hide();
});
function checkSumPrice(){
    var sumPrice = 0;
    for(var i = 0;i<$('.cart_money span').length;i++){
        sumPrice += Number($('.cart_money span').eq(i).text());
    };
    $('.sum_of_price').text((sumPrice).toFixed(2));
    $('.fact_price').text((sumPrice+Number($('.postage_price').text())).toFixed(2));
}
$(document).on('click','.plus-num',function(){
    var clo_nums = parseInt($(this).siblings('.clo-nums').text());
    var max_nums = parseInt($(this).siblings('.clo-nums').attr('abc'));
    if(clo_nums < max_nums){
        $(this).siblings('.clo-nums').text(clo_nums + 1);
        $(this).parent().siblings('.cart_doble').children('.cart_money').children('span').text($(this).siblings('.clo-nums').attr('price')*(clo_nums+1));
        checkSumPrice();
    }else{
        $('.tip_hide').html('库存上限'+max_nums+'件');
        $('.tip_hide').show().delay(800).hide(0);
        return false;
    }
});
$(document).on('click','.minus-num',function(){
  var clo_nums = parseInt($(this).siblings('.clo-nums').text());
  var max_nums = parseInt($(this).siblings('.clo-nums').attr('abc'));
  if(clo_nums > 0){
        $(this).siblings('.clo-nums').text(clo_nums - 1);
        $(this).parent().siblings('.cart_doble').children('.cart_money').children('span').text($(this).siblings('.clo-nums').attr('price')*(clo_nums-1));
        checkSumPrice();
  }else{
    return false;
  }
});
$('.choice_p').click(function(){
    var type = $(this).attr('type');
    var name = $('.check_user_name').val();
    var tel = $('.check_user_numb').val();
    var area_code = $('.check_user_prov').attr('abc');
    var address_info = $('.check_user_prov').val();
    var address_details = $('.edit-place-info').val();
    var size_ids = new Array;
    var num_ids = new Array;
    for(var i=0;i<$('.cart_size').length;i++){
        size_ids.push($('.cart_size span').eq(i).attr('abc'));
        num_ids.push($('.clo-nums').eq(i).text());
    }
    $.ajax({
        url:"/exchange/customer-order-pay",
        data:{
            name:name,
            tel:tel,
            area_code:area_code,
            address_details:address_details,
            address_info:address_info,
            size_ids:size_ids.toString(),
            num_ids:num_ids.toString()
        },
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
        },
        type:'POST',
        dataType:'json',
        success:function(data){
            if(data.result.success){
                if(type == "wx"){
                    window.location.href="/pay/wechat-pay-view/"+data.content;
                }else if(type = "alipay"){
                    window.location.href="/exchange/wechat-code/"+data.content;
                }
            }else{

            }
        }
    });
});
</script>
</html>
